package com.lwj.liwanjia.presenter;

import com.lwj.liwanjia.bean.ShangpinDetailBean;
import com.lwj.liwanjia.impl.ShangpinDetailView;
import com.lwj.liwanjia.model.ShangpinDetailModel;

import rx.Subscriber;

/**
 * Created by Administrator on 2017/9/29.
 */

public class ShangpinDetailPresenter {
    private ShangpinDetailModel shangpinDetailModel;
    private ShangpinDetailView shangpinDetailView;

    public ShangpinDetailPresenter(ShangpinDetailView shangpinDetailView) {
        this.shangpinDetailView = shangpinDetailView;
        shangpinDetailModel = new ShangpinDetailModel();
    }

    public void getShangpinDetail(String token,String shopGoodsCode, String commodityType) {
        if (shangpinDetailView != null) {
            shangpinDetailModel.getShangpinDetail(token,shopGoodsCode, commodityType, new Subscriber<ShangpinDetailBean>() {
                @Override
                public void onCompleted() {
                    shangpinDetailView.hideProgress();
                }

                @Override
                public void onError(Throwable e) {
                    shangpinDetailView.showError((Exception) e);
                    shangpinDetailView.hideProgress();
                }

                @Override
                public void onNext(ShangpinDetailBean shangpinDetailBean) {
                    shangpinDetailView.getShangpinDetail(shangpinDetailBean);
                }

                @Override
                public void onStart() {
                    super.onStart();
                    shangpinDetailView.showProgress();
                }
            });
        }
    }
}
